using Colorful;
using DG.Tweening;
using System;
using UnityEngine;

public class CameraManager : MonoBehaviour
{
	[Serializable]
	public class EditorReferences
	{
		public Grayscale grayscale;

		public CameraSmoothFollow smoothFollow;
	}

	public static CameraManager Instance;

	[SerializeField]
	public EditorReferences references = new EditorReferences();

	private Transform _cameraTransform;

	private Transform _target;

	private Tween _grayscaleTween;

	public Transform Target
	{
		get
		{
			return _target;
		}
		set
		{
			_target = value;
		}
	}

	private void Awake()
	{
		Instance = this;
		_cameraTransform = Camera.main.transform;
		references.grayscale.enabled = false;
	}

	public void SetTarget(Transform target)
	{
		_target = target;
		references.smoothFollow.target = target;
	}

	public void SetDistance(float distance, float height)
	{
		references.smoothFollow.SetDistance(distance);
		references.smoothFollow.SetHeight(height);
	}

	public void ToggleGrayscale(bool s)
	{
		if (_grayscaleTween != null)
		{
			_grayscaleTween.Kill();
		}
		if (s)
		{
			references.grayscale.enabled = true;
			references.grayscale.Amount = 0f;
			_grayscaleTween = DOTween.To(() => references.grayscale.Amount, delegate(float x)
			{
				references.grayscale.Amount = x;
			}, 1f, 0.3f);
		}
		else
		{
			references.grayscale.Amount = 1f;
			_grayscaleTween = DOTween.To(() => references.grayscale.Amount, delegate(float x)
			{
				references.grayscale.Amount = x;
			}, 0f, 0.3f).OnComplete(delegate
			{
				references.grayscale.enabled = false;
			});
		}
	}
}
